home *** CD-ROM | disk | FTP | other *** search
- /* RANDBWR.C --- p. 655 */
- #include <stdio.h>
- #include <dos.h>
- #define FCB_CREAT 0x16
- #define FCB_CLOSE 0x10
- char buffer[256] = "Testing randbwr...";
- main()
- {
- char input[80], far *old_dta;
- int option; /* Option for parsfnm */
- struct fcb fcb; /* File Control Block, FCB */
- int i, result;
- printf("Enter name of NEW file to which we will "
- "write two 128-byle records:\n(only drive and file "
- "name allowed, for example, A:MYFILE.DAT):");
- gets(input);
- /* parse file name using 'parsfnm' and an FCB */
- option = 1; /* means skip leading separators */
- parsfnm(input, &fcb, option);
- printf("Writing to\nDrive number: %d\n File name: %s\n",
- fcb.fcb_drive, fcb.fcb_name);
- /* Now create the file using DOS function 16h (this
- * is not the same as "_creat" which uses handles */
- if(bdosptr(FCB_CREAT, &fcb, 0) == -1)
- {
- printf("File creating file!\n");
- exit(1);
- }
- /* Save current disk transfer address and set up
- * the new one as the DTA */
- old_dta = getdta();
- setdta(buffer);
- /* Now set up the record size and start block */
- fcb.fcb_recsize = 128;
- fcb.fcb_random = 0L; /* start at record 0 */
- result = randbwr(&fcb, 2);
- printf("result = %d\n", result);
- if(result == 0)
- printf("Write ok\n");
- if(result == 1)
- printf("Disk full!\n");
- /* Finlly, close the file using DOS function 10h (this
- * is not the as "_close" which uses handles) */
- if(bdosptr(FCB_CLOSE, &fcb, 0) == -1)
- {
- printf("Error colsing file!\n");
- exit(1);
- }
- /* Reset DTA to old value */
- setdta(old_dta);
- }